package com.vmj.instructions.math;

import com.vmj.instructions.base.NoOperandsInstruction;
import com.vmj.rtda.Frame;
import com.vmj.rtda.OperandStack;

import java.math.BigDecimal;

/**
 * Created by yangshoujun on 2017/8/20 上午12:16.
 */
public class Frem extends NoOperandsInstruction {

    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.getOperandStack();
        float v2 = stack.popFloat();
        float v1 = stack.popFloat();
        if(v2 == 0) {
            throw new RuntimeException("除数为0.");
        }
        BigDecimal result = new BigDecimal(v1).remainder(new BigDecimal(v2)).setScale(4, BigDecimal.ROUND_HALF_UP);
        stack.pushFloat(result.floatValue());
    }
}
